package edu.friday.controller;

import edu.friday.common.base.BaseController;
import edu.friday.common.result.RestResult;
import edu.friday.common.result.TableDataInfo;
import edu.friday.model.SysUser;
import edu.friday.model.vo.SysUserVO;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;

@RestController
@RequestMapping("/demo")
public class DemoController extends BaseController {
    @PostMapping
    public RestResult add(){
        return toAjax(1);
    }

    @PutMapping
    public RestResult edit(){
        return toAjax(1);
    }

    @DeleteMapping
    public RestResult remove(){
        return toAjax(1);
    }

    @GetMapping(value = {"/","/{userId}"})
    public RestResult getInfo(@PathVariable(value = "userId",required = false)Long userId){
        RestResult ajax = RestResult.success();
        SysUser user = new SysUser();
        if(userId != null){
            user.setUserId(userId);
        }
        ajax.put("user",user);
        return ajax;
    }

    @GetMapping("/list")
    public TableDataInfo list(){
        return TableDataInfo.success(new ArrayList<>(),100);
    }

    @PostMapping("/vo")
    public RestResult testVo(@RequestBody @Valid SysUserVO sysUserVO){
        return RestResult.success(sysUserVO);
    }
}
